﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;

namespace KeanuMvc.Reference {

    public abstract class Html {

        public static string Form(string Name, string Action, string Method) {
            return string.Format(
                "<form id=\"{0}\" name=\"{0}\" action=\"{1}\" method=\"{2}\">",
                Name,
                Action,
                Method
                );
        }

        /// <summary>
        /// Generate string css embed file tag
        /// </summary>
        /// <param name="FilePath">Path file css</param>
        /// <param name="Additonal">Additonal tag of html if necessary</param>
        /// <returns>Return string css embed file tag</returns>
        public static string CssTagFile(string FilePath, string Additonal) {
            return string.Format(
               "<link href=\"{0}\" type=\"text/css\" rel=\"stylesheet\" {1}/>",
               FilePath,
               Additonal
               );
        }

        /// <summary>
        /// Generate string javascipt embed file tag
        /// </summary>
        /// <param name="FilePath"></param>
        /// <returns>Return string javascipt embed file tag</returns>
        public static string JavaScriptTagFile(string FilePath) {
            return string.Format(
              "<script type=\"text/javascript\" src=\"{0}\"></script>",
              FilePath
              );
        }

        /// <summary>
        /// Generate String html textbox tag
        /// </summary>
        /// <param name="Name">Name of textbox</param>
        /// <param name="ValueText">Value of textbox</param>
        /// <param name="ClassName">CSS Class name for textbox</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return String html textbox tag</returns>
        public static string TextBox(string Name, string ValueText, string ClassName, string Addtional) {
            return CreateInputType("text", Name, ValueText, ClassName, Addtional);
        }

        /// <summary>
        /// Generate String html textbox password tag
        /// </summary>
        /// <param name="Name">Name of textbox</param>
        /// <param name="ValueText">Value of textbox</param>
        /// <param name="ClassName">CSS Class name for textbox</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return String html textbox password tag</returns>
        public static string Password(string Name, string ValueText, string ClassName, string Addtional) {
            return CreateInputType("password", Name, ValueText, ClassName, Addtional);
        }

        /// <summary>
        /// Generate String html checkbox tag
        /// </summary>
        /// <param name="Name">Name of CheckBox</param>
        /// <param name="ValueText">Value of CheckBox</param>
        /// <param name="ClassName">CSS Class name for CheckBox</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return String html CheckBox tag</returns>
        public static string CheckBox(string Group, string Name, string ValueText, string ClassName, string Addtional, bool IsChecked) {
            Addtional = IsChecked ? Addtional + " checked='true'" : Addtional;
            return CreateInputRadioOrCheckBox("radio", Name, Group, ValueText, ClassName, Addtional);
        }

        /// <summary>
        /// Generate String html radio tag
        /// </summary>
        /// <param name="Name">Name of radio</param>
        /// <param name="ValueText">Value of radio</param>
        /// <param name="ClassName">CSS Class name for radio</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return string html radio tag</returns>
        public static string Radio(string Group, string Name, string ValueText, string ClassName, string Addtional, bool IsChecked) {
            Addtional = IsChecked ? Addtional + " checked='true'" : Addtional;
            return CreateInputRadioOrCheckBox("radio", Group, Name, ValueText, ClassName, Addtional);
        }

        /// <summary>
        /// Generate String html button submit tag
        /// </summary>
        /// <param name="Name">Name of submit</param>
        /// <param name="ValueText">Value of submit</param>
        /// <param name="ClassName">CSS Class name for submit</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return String html submit tag</returns>
        public static string ButtonSubmit(string pType, string Name, string ValueText, string ClassName, string Addtional) {
            return CreateInputType("submit", Name, ValueText, ClassName, Addtional);
        }

        public static string ButtonSubmitButton(string pType, string Name, string ValueText, string ClassName, string Addtional) {
            return string.Format("<button type=\"{0}\" class=\"{3}\" id=\"{1}\" name=\"{1}\" value=\"{2}\" {4}><span>{2}</span></button>",
                pType,
                Name,
                ValueText,
                ClassName,
                Addtional);
        }

        /// <summary>
        /// Generate String html label tag
        /// </summary>
        /// <param name="Name">Name of label</param>
        /// <param name="ValueText">Value of label</param>
        /// <param name="ClassName">CSS Class name for label</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return String html label password tag</returns>
        public static string Label(string Name, string ValueText, string ClassName, string Addtional) {
            return string.Format(
                "<label for=\"{0}\" class=\"{2}\" {3}>{1}</label>", 
                Name,
                ValueText,
                ClassName,
                Addtional
                );
        }

        /// <summary>
        /// Generate image html tag
        /// </summary>
        /// <param name="FilePath">Fath of file</param>
        /// <param name="ClassName">CSS Class Name of Image</param>
        /// <param name="Addtional">Additonal tag of html if necessary</param>
        /// <returns>Return image html tag</returns>
        public static string Image(string FilePath, string ClassName, string Addtional) {
            return string.Format("<img class=\"{0}\" src=\"{1}\" {2} />", ClassName, FilePath, Addtional);
        }

        public static string DropDown(string Name, string AdditonalTag, IList<object[]> DataSource, string SelectedValue) {
            string strResult = string.Format("<select name='{0}' id='{1}' {2}>", Name, Name, AdditonalTag);
            string strSelected = string.Empty;

            for (int i = 0; i < DataSource.Count; i++) {
                object[] item = DataSource[i];
                if (SelectedValue != string.Empty) {
                    if (SelectedValue == item[0].ToString())
                        strSelected = " selected";
                }
                strResult += string.Format("<option value='{0}'{1}>{2}</option>", item[0], strSelected, item[1]);
                strSelected = string.Empty;
            }
            strResult += "</select>";

            return strResult;
        }
       
        #region Private Methods

        private static string CreateInputType(string InputType, string Name, string ValueText, string ClassName, string Addtional) {
            return CreateInputControl(InputType, Name, Name, ValueText, ClassName, Addtional);
        }

        private static string CreateInputControl(string InputType, string Name, string Id, string ValueText, string ClassName, string Addtional) {
            ValueText = ValueText == string.Empty ? "##" + Name + "##" : ValueText;
            return string.Format(
                "<input name=\"{1}\" type=\"{0}\" class=\"{3}\" id=\"{5}\" value=\"{2}\" {4}/>",
                InputType,
                Name,
                ValueText,
                ClassName,
                Addtional,
                Id
                );
        }

        private static string CreateInputRadioOrCheckBox(string InputType, string Name, string Id, string ValueText, string ClassName, string Addtional) {
            return CreateInputControl(InputType, Name, Id, ValueText, ClassName, Addtional);
        }

        #endregion

        
    }
}